//
//  SoundManager.m
//  SoundDemo
//
//  Created by OC on 15/6/11.
//  Copyright (c) 2015年 YN. All rights reserved.
//

#import "SoundManager.h"
#import "YNIMFrameworkMacro.h"

@implementation SoundManager

- (id)initMessageVibrate
{
    self = [super init];
    
    if (self)
    {

        _soundId = kSystemSoundID_Vibrate;
    }
    
    return self;
}

- (id)initMessageSoundEffectWithName:(NSString *)fileName fileType:(NSString *)typeName
{
    self = [super init];
    
    if (self)
    {

        NSURL *fileURL = [[NSBundle mainBundle] URLForResource: @"fv"
                                                 withExtension: @"mp3"];
        if (fileURL != nil)
        {
            
            SystemSoundID currentSoundId;
            
            OSStatus error = AudioServicesCreateSystemSoundID((__bridge CFURLRef)fileURL, &currentSoundId);
            
            if (error == kAudioServicesNoError)
            {
                _soundId = currentSoundId;
            }
            else
            {
                debugLog(@"Failed to create sound");
            }
        }else{
            _soundId = 1002;
        }
    }
    
    return self;
    
}

- (void)play
{
    AudioServicesPlaySystemSound(_soundId);
}
@end
